package org.teamh.gui.ingame.effects;

import org.teamh.gui.engine.model.Model;

import static org.lwjgl.opengl.GL11.*;

public class LinearShot extends ShotEffect{
	private static final float DURATION = 200;
	
	private static final float SCALE = 1 / 32f;
	
	private Model model;
	private float floorAngle;
	
	public LinearShot(float startX, float startY, float startZ, float endX,
			float endY, float endZ, Model model) {
		super(startX, startY, startZ, endX, endY, endZ);
		this.model = model;
		
		float h = (float)Math.sqrt(getVecX() * getVecX() + getVecZ() * getVecZ());
		
		if(getVecZ() >= 0) {
			floorAngle = (float)Math.toDegrees(Math.asin(getVecX() / h)) - 90;
		} else {
			floorAngle = (float)Math.toDegrees(-Math.asin(getVecX() / h)) - 90;
		}
		
		
		setDuration(DURATION);
	}

	@Override
	public void render(float timeElapsed) {
		super.render(timeElapsed);
		
		glEnable(GL_TEXTURE_2D);
		
		glPushMatrix();
		{
			glTranslatef(getCurX(), getCurY(), getCurZ());
			glRotatef(floorAngle, 0, 1, 0);
			glScalef(SCALE, SCALE, SCALE);
			model.render();
		}
		glPopMatrix();
	}
}
